<?php
namespace App\Services\MyAddr;

use App\Services\MyAddr\MyAddr\MyAddrLogic;

/**
 * @Author: ws
 * @Date:   2019-02-20 16:23:45
 * @Last Modified by:   Marte
 */
class MyAddr
{

    /*用户收货地址列表*/
    public function myAddrList($data): array
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data, ['user_id'=>0]);
        ValidateMyAddr::checkValidate($data, ['user_id']);
        return (new MyAddrLogic())->myAddrList($data);

    }

    /*管理员收货地址列表（可搜用户id）*/
    public function adminMyAddrList($data): array
    {
        $data = init_array($data, ['keywords'=>'']);
        return (new MyAddrLogic())->adminMyAddrList($data);
    }


    //用户添加收货地址
    public function addMyAddr($data): array
    {
        $data = init_array($data, ['user_id' => 0,'addr' => '','name' => '','phone' => '','province' => '','city' => '','county' => '']);
        ValidateMyAddr::checkValidate($data, ['user_id','addr','name','phone']);
        return (new MyAddrLogic())->addMyAddr($data);
    }

    /*用户删除收货地址*/
    public function delMyAddr($data): array
    {
        $data = init_array($data, ['id' => 0,'user_id'=>0]);
        ValidateMyAddr::checkValidate($data, ['id','user_id']);
        return (new MyAddrLogic())->delMyAddr($data);
    }

    /*用户修改收货地址*/
    public function altMyAddr($data): array
    {
        $data = init_array($data, ['id' => 0,'user_id' => 0,'addr' => '','name' => '','phone' => '','province' => '','city' => '','county' => '']);
        ValidateMyAddr::checkValidate($data, ['id','user_id','addr','name','phone']);
        return (new MyAddrLogic())->altMyAddr($data);

    }

    /*用户查看某条详情*/
    public function myAddrInfo($data): array
    {
        $data = init_array($data, ['id'=>0]);
        ValidateMyAddr::checkValidate($data, ['id']);
        return (new MyAddrLogic())->myAddrInfo($data);
    }

     /*管理员删除收货地址*/
    public function adminDelMyAddr($data): array
    {
        $data = init_array($data, ['id'=>'']);
        return (new MyAddrLogic())->adminDelMyAddr($data);
    }

}
